import { BUNDLE_TYPE_ENUM, GAME_TYPE_ENUM, RELEASE_TYPE_ENUM } from "../base/EnumIndex";
import { Tools } from "../common/Tools";
import { GameManager } from "../manager/GameManager";
import { NetworkManager } from "../manager/NetworkManager";
import { UIManager } from "../manager/UIManager";
import { AdBase } from "./AdBase";
import AdManager_233 from "./AdManager_233";
import { AdManager_KS } from "./AdManager_KS";
import { AdManager_OV } from "./AdManager_OV";
import { AdManager_QQ } from "./AdManager_QQ";
import { AdManager_WX } from "./AdManager_WX";
import { AdManager_ZJ } from "./AdManager_ZJ";

export class AdManager {
    public static openAd: boolean = true;    //是否开启广告

    /** 233 平台游戏统一时间 */
    public static gameTime_huaQian: number = 999;

    /** 发布平台类型 releaseType值严格对应cdn渠道文件夹名称*/
    public static releaseType: RELEASE_TYPE_ENUM;
    /** 游戏类型  马甲包类型 */
    public static gameType: GAME_TYPE_ENUM;

    /**用户openId */
    public static openId: string = null;
    /**当前游戏id(文服字节为3) */
    public static gameId: number = 0;
    /**游戏类型（1微信 2抖音） */
    public static queryGameType: number = 2;
    /**视频上报接口返回的数据用于结束视频上报接口 */
    public static levelKey: string = null;
    /**直投参数 */
    public static cliKey: string = null;
    /** 巨量广告ClickID */
    public static clickID: string = null;
    /**直投项目id(当点击广告进来时和clickid一起拿到)*/
    public static projectId: string = null;
    /**广告id(当点击广告进来时和clickid一起拿到) */
    public static promotionId: string = null;
    /**快手广告主id */
    public static advertiser_id: number = null;

    /** 是否自定义logo */
    private static customLogo: boolean = false;
    private static sdk: AdBase = null;
    /** 初始化所有广告 */
    public static async initAds() {
        this.gameType = window["selectGame"]
        console.log("当前平台:", this.gameType)

        if (this.releaseType == RELEASE_TYPE_ENUM.ks) {
            Tools.storageKey += "_ks"
        } else if (this.releaseType == RELEASE_TYPE_ENUM.oppo_mini || this.releaseType == RELEASE_TYPE_ENUM.vivo_mini) {
            Tools.storageKey += "_qg";
        }
        this.initPlatfromType();
        this.initGameWrapper();
        this.loadAds();
        /**初始开启直播选关按钮为false */
        GameManager.ins.resetLiveLevelBtn();
    }
    /**我要变秃了 sdk接口 */
    private static async bianTu_sdk() {
        //初始化
        // await lt_sdk.lt_network.init();
        // console.log("sdk init success");
        //游戏初始化
    }

    /**乱斗大比拼 sdk接口 */
    private static async luanDou_sdk() {
        //初始化
        // await zs_sdk.zs_network.init();
        // console.log("sdk init success");
        //游戏初始化
    }
    /** 初始化当前打包的平台 */
    public static initPlatfromType() {
        switch (cc.sys.platform) {
            case cc.sys.DESKTOP_BROWSER:
            case cc.sys.MOBILE_BROWSER:
                if (window["h5api"]) {
                    this.releaseType = RELEASE_TYPE_ENUM.h5_4399;
                } else {
                    // this.releaseType = cc.sys.platform == cc.sys.DESKTOP_BROWSER ? RELEASE_TYPE_ENUM.local : RELEASE_TYPE_ENUM.h5;
                    this.releaseType = RELEASE_TYPE_ENUM.h5;
                }
                break;
            case cc.sys.BYTEDANCE_GAME:
                this.releaseType = RELEASE_TYPE_ENUM.bytedance;
                break;
            case cc.sys.WECHAT_GAME:
                if (window['ks']) {  //快手 打微信包
                    this.releaseType = RELEASE_TYPE_ENUM.ks;
                } else if (window['qq']) {
                    this.releaseType = RELEASE_TYPE_ENUM.qq_mini;
                } else if (window['wx']) {
                    this.releaseType = RELEASE_TYPE_ENUM.wechat;
                }
                break;
            case cc.sys.OPPO_GAME:
                this.releaseType = RELEASE_TYPE_ENUM.oppo_mini;
                break;
            case cc.sys.VIVO_GAME:
                this.releaseType = RELEASE_TYPE_ENUM.vivo_mini;
                break;
            case cc.sys.ANDROID:
                this.releaseType == RELEASE_TYPE_ENUM.android_233;
                break;
            default:
                this.releaseType = RELEASE_TYPE_ENUM.local;
                break;
        }
        console.log("当前平台:", this.releaseType, cc.sys.platform);
    }
    /** 不同马甲包 对应初始化 */
    public static initGameWrapper() {
        this.customLogo = false;
        switch (this.gameType) {
            case GAME_TYPE_ENUM.NAO_DONG_TIAN_HUA_BAN:
                switch (this.releaseType) {
                    case RELEASE_TYPE_ENUM.ks:
                    case RELEASE_TYPE_ENUM.wechat:
                    case RELEASE_TYPE_ENUM.oppo_mini:
                        this.customLogo = true;
                        break;
                    default:
                        break;
                }
                break;
            case GAME_TYPE_ENUM.WEN_ZI_WO_FU_LE:
                switch (this.releaseType) {
                    case RELEASE_TYPE_ENUM.wechat:
                        this.customLogo = true;
                        break;
                    default:
                        break;
                }
                break;
            case GAME_TYPE_ENUM.WO_YAO_BIAN_TU_LE:
                // case GAME_TYPE_ENUM.WAN_DAN_ZHANG_NAO_ZI_LE:
                switch (this.releaseType) {
                    case RELEASE_TYPE_ENUM.ks:
                        this.customLogo = true;
                        break;
                    case RELEASE_TYPE_ENUM.bytedance:
                        // this.bianTu_sdk();
                        break
                    default:
                        break;
                }
                break;
            // case GAME_TYPE_ENUM.Luan_DOU_DA_BI_PIN:
            //     this.luanDou_sdk();
            //     break;
            // case GAME_TYPE_ENUM.NAO_LI_YONG_ZHE:
            //     this.naoLiLogin();
            //     break;
            default:
                break;
        }
    }
    /** 加载所有广告 */
    private static loadAds() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                this.sdk = AdManager_ZJ.ins;
                break;
            case RELEASE_TYPE_ENUM.wechat:
                this.sdk = AdManager_WX.ins;
                break;
            case RELEASE_TYPE_ENUM.ks:
                this.sdk = AdManager_KS.ins;
                break;
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
                this.sdk = AdManager_OV.ins;
                break;
            case RELEASE_TYPE_ENUM.qq_mini:
                this.sdk = AdManager_QQ.ins;
                break;
            case RELEASE_TYPE_ENUM.android_233:
                this.sdk = AdManager_233.ins;
                break;
            default:
                break;
        }
        if (this.sdk) {
            this.sdk.gameType = this.gameType;
            this.sdk.loadAllAd();
        }
    }
    /** 获取logo所在文件夹 */
    public static getLogoFolderName(): string {
        return this.customLogo ? this.releaseType : "common";
    }
    /** Banner 广告 */
    public static showBanner() {
        if (!this.openAd) { return; }

        switch (this.releaseType) {
            // case RELEASE_TYPE_ENUM.bytedance:
            // case RELEASE_TYPE_ENUM.wechat:
            // case RELEASE_TYPE_ENUM.ks:
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.android_233:
                // case RELEASE_TYPE_ENUM.wechat:
                this.sdk.showBanner();
                break;
            default:
                break;
        }
    }
    /** 隐藏 Banner 广告 */
    public static hideBanner() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            // case RELEASE_TYPE_ENUM.bytedance:
            // case RELEASE_TYPE_ENUM.wechat:
            // case RELEASE_TYPE_ENUM.ks:
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.android_233:
                this.sdk.hideBanner();
                break;
            default:
                break;
        }
    }
    /** 插屏广告 */
    public static showIntersAd() {
        if (!this.openAd) { return; }

        switch (this.releaseType) {
            // case RELEASE_TYPE_ENUM.bytedance:
            // case RELEASE_TYPE_ENUM.wechat:
            // case RELEASE_TYPE_ENUM.ks:
            // case RELEASE_TYPE_ENUM.oppo_mini:
            // case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.android_233:
                // case RELEASE_TYPE_ENUM.wechat:
                this.sdk.showIntersAd();
                break;
            default:
                break;
        }
    }
    /**
     * 播放视频激励广告
     * @param finishBack 视频完成回调
     * @param errorBack  视频失败回调
     */
    public static showVideoAd(finishBack?: Function, errorBack?: Function, data?: number, canCostFreeNum: boolean = true) {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                this.sdk.showVideoAd(finishBack, errorBack, data, canCostFreeNum);
                break;
            case RELEASE_TYPE_ENUM.wechat:
            case RELEASE_TYPE_ENUM.ks:
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.android_233:
                this.sdk.showVideoAd(finishBack, errorBack, null, canCostFreeNum);
                break;
            case RELEASE_TYPE_ENUM.h5_4399:
                console.log("调用4399API");
                window["h5api"].playAd((obj: any) => {
                    if (obj.code === 10000) {
                        console.log("开始播放广告");
                    } else if (obj.code === 10001) {
                        console.log("播放结束");
                        if (finishBack) { finishBack(); };
                    } else {
                        console.log("广告异常");
                    }
                });
                break;
            default:
                if (finishBack) { finishBack(); };
                break;
        }
    }
    /** 视频播放完成 */
    public static finishVideo() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.android_233:
                this.sdk.finishVideo();
                break;
            default:
                break;
        }
    }
    /** 视频播放失败 */
    public static errorVideo() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.android_233:
                this.sdk.errorVideo();
                break;
            default:
                break;
        }
    };
    /** 开始录屏 */
    public static startVideoScreen() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
                this.sdk.createVideoScreen();
                break;
            default:
                break;
        }
    };
    /** 停止录屏 */
    public static stopVideoScreen() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
                this.sdk.stopVideoScreen();
                break;
            default:
                break;
        }
    };
    /** 分享录屏 */
    public static shareVideoScreen() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
                this.sdk.shareScreenVideo();
                break;
            case RELEASE_TYPE_ENUM.wechat:
            case RELEASE_TYPE_ENUM.qq_mini:
                this.sdk.shareFriends();
                break;
            default:
                UIManager.ins.showToast("分享成功");
                break;
        }
    };
    /** 分享好友 */
    public static shareFriends() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
            case RELEASE_TYPE_ENUM.wechat:
            case RELEASE_TYPE_ENUM.qq_mini:
                this.sdk.shareFriends();
                break;
            default:
                UIManager.ins.showToast("分享成功");
                break;
        }
    };

    /** 获取排行榜 */
    public static getRankList() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                this.sdk.getRankList();
                break;
            default:
                break;
        }
    };

    /** 上传排行榜分数 */
    public static setRankData(score: number) {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                this.sdk.setRankData(score);
                break;
            default:
                break;
        }
    };

    public static addTable(callback: Function) {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
                this.sdk.addTable(() => callback());
                break;
            default:
                callback();
                Tools.setStorage('addShortcut', true);
                break;
        }
    }

    public static addSubscribe(callback: Function) {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
                this.sdk.addSubscribe(() => callback());
                break;
            default:
                callback();
                Tools.setStorage('subscribeTime', true);
                break;
        }
    }

    /**展示更多游戏 */
    public static showMoreGame() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            // case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
                this.sdk.showMoreGame();
                break;
            default:
                break;
        }
    }

    /**隐藏更多游戏 */
    public static hideMoreGame() {
        if (!this.openAd) { return; }
        switch (this.releaseType) {
            // case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
                this.sdk.hideMoreGame();
                break;
            default:
                break;
        }
    }
    public static exit() {
        switch (this.releaseType) {
            // case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
                this.sdk.exit();
                break;
            default:
                break;
        }

    }

    /** 上报自定义埋点 */
    public static umengEvent(eventName: string, eventData?: { tag?: string, name?: string, value?: string, leveltime?: number }) {
        console.log(eventName, eventData);
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                if (this.gameType == GAME_TYPE_ENUM.NAO_DONG_TIAN_HUA_BAN && window["uma"]) {
                    if (eventData) {
                        window["uma"].trackEvent(eventName, eventData)
                    } else {
                        window["uma"].trackEvent(eventName)
                    }
                }
                break;
            default:
                break;
        }
    };
    /** 是否展示排行榜 */
    public static isShowRankBtn() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                return AdManager_ZJ.ins.isRank;
            default:
                return false;
        }
    }
    /** 是否展示分享 */
    public static isShowShareBtn() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.h5_4399:
            case RELEASE_TYPE_ENUM.h5:
            case RELEASE_TYPE_ENUM.android:
                // case RELEASE_TYPE_ENUM.local:
                return false;
            default:
                return true;
        }
    }

    /** 是否展示 过关后不弹胜利界面 重新开始本关*/
    public static isWinReGameBtn(callback: Function) {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.h5:
            case RELEASE_TYPE_ENUM.local:
                callback(true);
                break;
            default:
                callback(false);
                break;
        }
    }

    /** 是否展示 搜索关卡功能*/
    public static isShowSearch(callback: Function) {
        if (this.gameId === 5) {
            callback(true);
            return;
        }
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.h5:
            case RELEASE_TYPE_ENUM.local:
                callback(true);
                break;
            default:
                callback(false);
                break;
        }
    }

    /** 是否展示 过关后不弹胜利界面 重新开始本关*/
    public static isLiveLevelBtn(callback: Function) {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.h5:
            case RELEASE_TYPE_ENUM.local:
                callback(true);
                break;
            default:
                callback(false);
                break;
        }
    }

    /** 是否展示添加桌面 */
    public static isShowAddShortcutBtn(callback: Function) {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
            case RELEASE_TYPE_ENUM.ks:
                this.sdk.isAddTable(callback);
                break;
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.h5_4399:
            case RELEASE_TYPE_ENUM.android:
            case RELEASE_TYPE_ENUM.h5:
            case RELEASE_TYPE_ENUM.wechat:
                // case RELEASE_TYPE_ENUM.local:
                callback(false);
                break;
            default:
                let isAdd = Tools.getStorage('addShortcut');
                callback(!isAdd);
                break;
        }
    }
    /** 是否展示礼包按钮 */
    public static isShowGiftBtn(callback: Function) {
        if (this.releaseType === RELEASE_TYPE_ENUM.bytedance) {
            AdManager_ZJ.ins.checkScene(callback)
        } else if (this.releaseType === RELEASE_TYPE_ENUM.wechat || this.releaseType === RELEASE_TYPE_ENUM.ks) {
            console.log("检查签到入口开启", this.releaseType, RELEASE_TYPE_ENUM.wechat);
            callback(false)
        }
        return false;
    }

    /**是否展示常玩按钮 */
    public static isShowChangWanBtn(callback: Function) {
        if (this.releaseType === RELEASE_TYPE_ENUM.ks) {
            AdManager_KS.ins.checkCommonUse((active) => {
                console.log("是否打开常玩按钮1：", active);
                callback(active);
            });
            return;
        }
        return false;
    }

    /**设为常玩 */
    public static addCommonUse(callback: Function) {
        if (this.releaseType === RELEASE_TYPE_ENUM.ks) {
            AdManager_KS.ins.addCommonUse(callback);
        }
    }

    /**是否进入复访UI */
    public static fuFangFinished() {
        return AdManager_ZJ.ins.fuFangFinished;
    }
    /** 字节 复访 */
    public static fuFang() {
        if (this.releaseType != RELEASE_TYPE_ENUM.bytedance) return;
        AdManager_ZJ.ins.fuFang();
    }
    /** 字节跳转 */
    public static navigateToScene(callback: Function) {
        if (this.releaseType != RELEASE_TYPE_ENUM.bytedance) return;
        AdManager_ZJ.ins.navigateToScene(callback)
    }
    /** 字节检测是否从侧边栏进入 */
    public static isFromSideBar(callback: Function) {
        if (this.releaseType != RELEASE_TYPE_ENUM.bytedance) return;
        AdManager_ZJ.ins.isFromSideBar(callback)
    }
    /** 字节收藏功能 */
    public static favoriteGuide(callback: Function) {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                AdManager_ZJ.ins.showFavoriteGuide(callback)
                break;
            default:
                break;
        }
    }
    /** 是否展示 收藏按钮 */
    public static isShowFavouriteBtn() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.bytedance:
                return true;
                break;
            default:
                break;
        }
        return false;
    }
    /** 是否展示闪屏 */
    public static isShowFlash() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
            case RELEASE_TYPE_ENUM.ks:
                return true;
            default:
                return false;
        }
    }
    /** 是否展示隐私政策和用户协议 */
    public static isShowPrivacy() {
        switch (this.releaseType) {
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
            case RELEASE_TYPE_ENUM.qq_mini:
                return true;
            default:
                return false;
        }
    }

    public static showAgreeUI() {
        if (!this.isShowPrivacy()) return;
        if (!Tools.getStorage("isAgree")) {
            if (this.releaseType == RELEASE_TYPE_ENUM.qq_mini) {
                UIManager.ins.showPop('agreeUI', BUNDLE_TYPE_ENUM.HOME);
            } else {
                UIManager.ins.showPop('privacyUI', BUNDLE_TYPE_ENUM.HOME);
            }
        }
    }
    public static showPrivacyUI() {
        if (this.releaseType == RELEASE_TYPE_ENUM.qq_mini) {
            if (Tools.getStorage("isAgress") === 1) {
                UIManager.ins.showPop("privacyUI", BUNDLE_TYPE_ENUM.HOME);
            }
        }
    }

    public static send_JuLiang() {
        if (this.releaseType === RELEASE_TYPE_ENUM.bytedance) {
            NetworkManager.send_JuLiang("active", AdManager_ZJ.ins.clickID);
        }
    }
    /** 关卡页面 是否解锁全部 */
    public static isUnlockAllLevel() {
        switch (this.releaseType) {//OV渠道默认全部解锁
            case RELEASE_TYPE_ENUM.oppo_mini:
            case RELEASE_TYPE_ENUM.vivo_mini:
                return true;
            default:
                return false;
        }
    }

    /**文服 字节视频上报 
     * @param videoType 1提示 2答案 3解锁关卡 4加时 5跳过本关 6加步数
    */
    public static reportVideo(videoType: number, levelId: number, levelName: string) {
        if (AdManager.openId && AdManager.gameId != 0) {
            console.log("当前关卡索引:" + levelId + "当前关卡名称：" + levelName);
            NetworkManager.reportVideo(AdManager.gameId, AdManager.openId, videoType, AdManager.queryGameType, levelId, levelName, (data) => {
                AdManager.levelKey = data;
            }, AdManager.clickID, AdManager.cliKey);
        }
    }

    /**文服 字节视频结束上报*/
    public static reportOverVideo(levelId: number, levelName: string) {
        console.log("当前关卡索引:" + levelId + "当前关卡名称：" + levelName);
        if (AdManager.openId && AdManager.gameId != 0) {
            NetworkManager.reportOverVideo(AdManager.gameId, AdManager.openId, AdManager.levelKey, levelId, levelName, AdManager.clickID, AdManager.projectId, AdManager.promotionId, AdManager.advertiser_id);
        }
    }

    /**文服 游戏时长上报
     * @param type 1开始时间 2结束时间
     */
    public static reportGameTime(type) {
        if (AdManager.openId && AdManager.gameId != 0) {
            NetworkManager.reportGameTime(AdManager.gameId, AdManager.openId, type, this.clickID, this.queryGameType, this.projectId, this.advertiser_id);
        }
    }

    /**文服 用户关卡数据上报接口 */
    public static reportLevel(levelId: number, levelName: string, isOver: number) {
        console.log("当前关卡索引:" + levelId + "当前关卡名称：" + levelName);
        if (AdManager.openId && AdManager.gameId != 0) {
            NetworkManager.reportLevel(AdManager.gameId, AdManager.openId, levelId, levelName, isOver);
        }
    }

    /**文服 返回首页上报 */
    public static reportHomeView() {
        if (AdManager.openId && AdManager.gameId != 0) {
            NetworkManager.reportHomeView(AdManager.gameId, AdManager.openId);
        }
    }

    /**文服  在线获取关卡配置*/
    public static loadServerJson(callback) {
        if (this.sdk.gameId != 0) {
            console.log("xxxxxxxxxxxxxxxxxxxxxxgameID:", this.sdk.gameId);
            NetworkManager.getConfigById(this.sdk.gameId, (lvJson) => {
                callback(lvJson);
            });
        } else if (this.gameType == GAME_TYPE_ENUM.Luan_DOU_DA_BI_PIN) {
            // let promise = zs_sdk.zs_network.config(false, "levelCfg");
            // promise.then((data) => {
            //     console.log(data);
            //     let lvJson = JSON.parse(data.levelCfg[0]["config_info"])
            //     callback(lvJson);
            // }).catch((error) => {
            //     console.log(error);
            // });
        }
    }

    /**退出本关 */
    public static exitLv(levelName: string) {
        if (AdManager.openId && AdManager.gameId != 0) {
            NetworkManager.exitLevel(AdManager.gameId, AdManager.openId, levelName);
        }
    }

    /** 震动 */
    public static vibrate(num: number) {
        switch (this.releaseType) {//OV渠道默认全部解锁
            case RELEASE_TYPE_ENUM.android:
            case RELEASE_TYPE_ENUM.android_233:
            case RELEASE_TYPE_ENUM.google:
                // jsb.reflection.callStaticMethod("com/cocos/game/AppActivity", "vibrateIphone", "(I)V", num);
                break;
            case RELEASE_TYPE_ENUM.ios:
                // jsb.reflection.callStaticMethod("com/cocos/game/AppActivity", "vibrateIphone", "(I)V", num);
                break;
            case RELEASE_TYPE_ENUM.wechat:
            case RELEASE_TYPE_ENUM.ks:
            case RELEASE_TYPE_ENUM.bytedance:
                this.sdk.vibrate(num)
                return true;
            default:
                if (navigator.vibrate) {
                    navigator.vibrate(num);
                }
                return false;
        }
    }

    //脑力勇者相关sdk接口
    /**脑力勇者 登录 */
    public static naoLiLogin() {
        // if (AdManager.gameType == GAME_TYPE_ENUM.NAO_LI_YONG_ZHE) {
        //     ShufenManager.initData();
        //     let uid = new Date().getTime() + "naoLi";
        //     ShufenManager.report({ "event": ShufenEvent.login, "userId": uid });
        // }
    }

    /**脑力勇者 视频上报接口 
     * @param type 1:展示;2:拉取;3:拉取成功;4播放完成
    */
    public static naoLiReportVideo(type: number, name: string) {
        // if (AdManager.gameType == GAME_TYPE_ENUM.NAO_LI_YONG_ZHE) {
        //     let unitId = new Date().getTime() + "";
        //     if (type == 1 || type == 2) {
        //         unitId = "video";
        //     }
        //     ShufenManager.report({ event: ShufenEvent.video, name: name, type: type, unitId: unitId });
        // }
    }

}
window['AdManager'] = AdManager;

export var ReportType = {
    ENTER_LEVEL: "enter_lv",
    OVER_LEVEL: "over_lv",
    CLICK_ADS: "click_ads",
}
